#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    struct ListNode* curA = headA;
    struct ListNode* curB = headB;
    int len1 = 1;
    int len2 = 1;
    if (!curA || !curB)
        return NULL;
    if (curB == NULL && curA->next == 0)
        return curA;
    while (curA->next)
    {
        len1++;
        curA = curA->next;
    }
    while (curB->next)
    {
        len2++;
        curB = curB->next;
    }
    if (curA != curB)
        return NULL;
    int gap = abs(len1 - len2);
    struct ListNode* shortNode = headA;
    struct ListNode* longNode = headB;
    if (len1 > len2)
    {
        shortNode = headB;
        longNode = headA;
    }
    while (gap--)
    {
        longNode = longNode->next;
    }
    while (longNode != shortNode)
    {
        longNode = longNode->next;
        shortNode = shortNode->next;
    }
    return shortNode;
}